package com.team.kaidb.customview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.team.kaidb.R;

/**
 * Created by Wj on 15/7/2.
 *  上面是图片，下面是文字
 */
public class TextImage extends LinearLayout {

    private TextView tv_text;
    private ImageView img_icon;

    public TextImage(Context context) {
        super(context);
    }

    public TextImage(Context context, AttributeSet attrs) {
        super(context, attrs);
        View view = View.inflate(context, R.layout.img_txt_lay, null);
        addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        initView();
    }
    private void initView(){
        tv_text = (TextView)findViewById(R.id.textView_img_txt);
        img_icon = (ImageView) findViewById(R.id.imageView_img_txt);
    }
    public void setText(String text){
        img_icon.setVisibility(View.GONE);
        tv_text.setVisibility(View.VISIBLE);
        tv_text.setText(text);
    }
    public void setContent(String text,int src){
        img_icon.setVisibility(View.VISIBLE);
        tv_text.setVisibility(View.VISIBLE);
        tv_text.setText(text);
        img_icon.setImageResource(src);
    }
    public void setImage(int src){
        img_icon.setVisibility(View.VISIBLE);
        tv_text.setVisibility(View.GONE);
        img_icon.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        img_icon.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
        img_icon.setImageResource(src);
    }

}
